package com.jfinal_demo.app.services;

import com.jfinal.kit.HashKit;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal_demo.app.model.User;

public class UserService extends BaseService {
    public void register(String userName, String plainPassword) {
        Kv kv = new Kv().set("userName", userName);
        User existUser = User.dao.findFirst(Db.getSqlPara("user.one", kv));
        if (existUser != null)
            return;
        User user = new User();
        user.setUserName(userName);
        user.setPassword(HashKit.md5(plainPassword));
        user.save();
    }

    public User getUser(String userName, String plainPassword) {
        Kv kv = new Kv()
                .set("userName", userName)
                .set("password", HashKit.md5(plainPassword));
        User user = User.dao.findFirst(Db.getSqlPara("user.one", kv));
        return user;
    }
}
